//
//  ZTAirMonitoringBottomCell.m
//  YSSmartHome
//
//  Created by yanghao on 2017/4/5.
//  Copyright © 2017年 yahaong. All rights reserved.
//

#import "ZTAirMonitoringBottomCell.h"
#import "PNChart.h"
#import "ZTAirChartView.h"
#import "ZTAirButton.h"
#import "ZTAirRecordButton.h"
#import "YSCommon.h"

@interface ZTAirMonitoringBottomCell ()
@property (nullable, nonatomic, strong) ZTAirRecordButton* mBtnRecord;
@property (nullable, nonatomic, strong) UIScrollView* mChartScrollView;
@property (nullable, nonatomic, strong) UIView* mChartContentView;
@property (nullable, nonatomic, strong) ZTAirChartView* pmChartView;
@property (nullable, nonatomic, strong) ZTAirChartView* formaldehydeChartView;
@property (nullable, nonatomic, strong) ZTAirChartView* tempChartView;

@property (nullable, nonatomic, strong) ZTAirButton* mBtnLastday;
@property (nullable, nonatomic, strong) ZTAirButton* mBtnLastWeak;
@property (nullable, nonatomic, strong) ZTAirButton* mBtnLastMouth;
@end
@implementation ZTAirMonitoringBottomCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = [UIColor blueColor];
        [self initSubViews];
    }
    return self;
}
- (void)initSubViews
{
    [self.contentView addSubview:self.mBtnRecord];
    [self.contentView addSubview:self.mBtnLastday];
    [self.contentView addSubview:self.mBtnLastWeak];
    [self.contentView addSubview:self.mBtnLastMouth];
    [self.contentView addSubview:self.mChartScrollView];
    [self.mChartScrollView addSubview:self.mChartContentView];
    [self.mChartContentView addSubview:self.pmChartView];
    [self.mChartContentView addSubview:self.formaldehydeChartView];
    [self.mChartContentView addSubview:self.tempChartView];
    [self layoutPageSubViews];
}

- (void)layoutPageSubViews
{
    [self.mBtnRecord mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.trailing.equalTo(self.contentView);
        make.height.equalTo(kIphoneSize_Height(53));
    }];
    [self.mBtnLastday mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mBtnRecord.bottom);
        make.leading.equalTo(self);
        make.height.equalTo(kIphoneSize_Height(44));
        make.width.equalTo(kScreenWidth / 3);
    }];
    [self.mBtnLastWeak mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.height.width.equalTo(self.mBtnLastday);
        make.leading.equalTo(self.mBtnLastday.trailing);
    }];
    [self.mBtnLastMouth mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.height.width.equalTo(self.mBtnLastday);
        make.leading.equalTo(self.mBtnLastWeak.trailing);
    }];
    [self.mChartScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.bottom.equalTo(self.contentView);
        make.top.equalTo(self.mBtnLastday.bottom);
    }];
    [self.mChartContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.mChartScrollView);
        make.width.equalTo(self.mChartScrollView );
    }];
    [self.pmChartView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.mChartContentView).offset(kIphoneSize_Widith(10));
        make.trailing.equalTo(self.mChartContentView).offset(kIphoneSize_Widith(-10));
        make.top.equalTo(self.mChartContentView);
        make.height.equalTo(kIphoneSize_Height(185));
    }];
    [self.formaldehydeChartView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.height.leading.equalTo(self.pmChartView);
        make.top.equalTo(self.pmChartView.bottom).offset(kIphoneSize_Height(20));
    }];
    [self.tempChartView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.height.leading.equalTo(self.formaldehydeChartView);
        make.top.equalTo(self.formaldehydeChartView.bottom).offset(kIphoneSize_Height(20));
    }];
    [self.mChartContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.tempChartView);
    }];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
#pragma mark - event response
- (void)recordBtnTapped
{
//    if (self.delegate && [self.delegate respondsToSelector:@selector(airMonitoringBottomCellRecordTapped:)])
//    {
//        [self.delegate airMonitoringBottomCellRecordTapped:self];
//    }
    [self.pmChartView setXlables:nil];
}
#pragma mark - getters and setters
- (ZTAirChartView *)pmChartView
{
    if (!_pmChartView) {
        _pmChartView = [[ZTAirChartView alloc]initWithXlabels:@[@"3:00",@"6:00",@"9:00",@"12:00",@"15:00",@"18:00",@"21:00",@"24:00"] block:nil];
        _pmChartView.topBackgroundImage = [UIImage imageNamed:@"pm_top_background"];
        _pmChartView.title = @"PM";
    }
    return _pmChartView;
}
- (ZTAirChartView *)formaldehydeChartView
{
    if (!_formaldehydeChartView) {
        _formaldehydeChartView = [[ZTAirChartView alloc]initWithXlabels:@[@"3:00",@"6:00",@"9:00",@"12:00",@"15:00",@"18:00",@"21:00",@"24:00"] block:^NSString * _Nullable(CGFloat value) {
            return [NSString stringWithFormat:@"%.3f",value / 1000 * 0.833];
        }];
        _formaldehydeChartView.topBackgroundImage = [UIImage imageNamed:@"formaldehyde_top_background"];
        _formaldehydeChartView.title = @"甲醛";
    }
    return _formaldehydeChartView;
}
- (ZTAirChartView *)tempChartView
{
    if (!_tempChartView) {
        _tempChartView = [[ZTAirChartView alloc]initWithXlabels:@[@"3:00",@"6:00",@"9:00",@"12:00",@"15:00",@"18:00",@"21:00",@"24:00"]block:^NSString * _Nullable(CGFloat value) {
            return [NSString stringWithFormat:@"%.1f",value / 10.0];
        }];
        _tempChartView.topBackgroundImage = [UIImage imageNamed:@"temp_top_background"];
        _tempChartView.title = @"温度";
    }
    return _tempChartView;
}
- (ZTAirRecordButton *)mBtnRecord
{
    if (!_mBtnRecord) {
        _mBtnRecord = [[ZTAirRecordButton alloc]initWithTitle:@"检测记录" imageName:@"新设备-空气检测器3-下滑"];
        [_mBtnRecord addTarget:self action:@selector(recordBtnTapped) forControlEvents:UIControlEventTouchUpInside];
    }
    return _mBtnRecord;
    
}
- (ZTAirButton *)mBtnLastday
{
    if (!_mBtnLastday) {
        _mBtnLastday = [[ZTAirButton alloc]init];
        [_mBtnLastday setImage:[UIImage imageNamed:@"新设备-空气检测器4-选择"] forState:UIControlStateNormal];
        [_mBtnLastday setTitle:@"最近一天" forState:UIControlStateNormal];
    }
    return _mBtnLastday;
}
- (ZTAirButton *)mBtnLastWeak
{
    if (!_mBtnLastWeak) {
        _mBtnLastWeak = [[ZTAirButton alloc]init];
        [_mBtnLastWeak setImage:[UIImage imageNamed:@"新设备-空气检测器4-选择"] forState:UIControlStateNormal];
        [_mBtnLastWeak setTitle:@"最近一周" forState:UIControlStateNormal];
    }
    return _mBtnLastWeak;
}
- (ZTAirButton *)mBtnLastMouth
{
    if (!_mBtnLastMouth) {
        _mBtnLastMouth = [[ZTAirButton alloc]init];
        [_mBtnLastMouth setImage:[UIImage imageNamed:@"新设备-空气检测器4-选择"] forState:UIControlStateNormal];
        [_mBtnLastMouth setTitle:@"最近一月" forState:UIControlStateNormal];
    }
    return _mBtnLastMouth;
}
- (UIScrollView *)mChartScrollView
{
    if (!_mChartScrollView) {
        _mChartScrollView = [[UIScrollView alloc]init];
        _mChartScrollView.showsVerticalScrollIndicator = NO;
        _mChartScrollView.showsHorizontalScrollIndicator = NO;
    }
    return _mChartScrollView;
}
- (UIView *)mChartContentView
{
    if (!_mChartContentView) {
        _mChartContentView = [[UIView alloc]init];
    }
    return _mChartContentView;
}
@end
